package it.tukano.swingdeco;

import java.awt.Color;
import java.awt.Font;
import javax.swing.Icon;
import javax.swing.JLabel;

/**
 * Extended JLabel
 * @author pgi
 */
public class JLabelExt extends JLabel {
    
    /* default serial version code */
    private static final long serialVersionUID = 0;
    
    public JLabelExt() {}
    
    public JLabelExt(Object text) {
        super(String.valueOf(text));
    }

    /**
     * Instance initializer
     */
    public JLabelExt(String text) {
        super(text);
    }
    
    public JLabelExt withBackground(Color c) {
        setOpaque(true);
        setBackground(c);
        return this;
    }
    
    public JLabelExt alignLeft() {
        setHorizontalAlignment(JLabel.LEFT);
        return this;
    }
    
    public JLabelExt scaleFont(double factor) {
        Font font = getFont();
        font = font.deriveFont(font.getSize2D() * (float) factor);
        setFont(font);
        return this;
    }
    
    public JLabelExt withIcon(Icon icon) {
        setIcon(icon);
        return this;
    }

    public JLabelExt alignCenter() {
        setHorizontalAlignment(JLabel.CENTER);
        return this;
    }

    /**
     * Set opaqueness to true and return this
     */
    public JLabelExt opaque() {
        setOpaque(true);
        return this;
    }
}
